package CTRLayer;
import java.sql.Date;

import DBLayer.*;
import ModelLayer.*;

public class Controller {
	private IFDBCustomer customerDB;
	private IFDBSupplier supplierDB;
	private IFDBLocation locationDB;
	private IFDBSalesLine salesLineDB;
	private IFDBSalesOrder salesOrderDB;
	private IFDBProduct productDB;
	
	public Controller(){
		customerDB = new DbCustomer();
		supplierDB = new DbSupplier();
		locationDB = new DbLocation();
		salesOrderDB = new DbSalesOrder();
		productDB = new DbProduct();
		
	}
	

	
	
	public boolean getCustomer(String lName)
	{
		if(customerDB.getCustomerByName(lName)==null)
			return false;
		else
			return true;
	}

	public int newCustomer(String id, String lName, String fName, String phone, String address, String countryZip, String cityZip)
	{
		int result = -1;
		Customer cus = new Customer();
		cus.setSurname(lName);
		cus.setName(fName);
		cus.setPhoneNO(phone);
		cus.setAddress(address);
		cus.setLocation(locationDB.getCityByCodeZip(cityZip, countryZip));
		try {
			result = customerDB.insertCustomer(cus);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		//make something with this in the model layer / DB and add to table in customers
	}
	
	public String custInfo(String id) 
	{
        return customerDB.getCustomerById(Integer.valueOf(id)).getName() + " " + customerDB.getCustomerById(Integer.valueOf(id)).getSurname();
	}

	public boolean deleteCustomer(String idSelected)
	{
		return true; //if the deleting finished and do the deleting part
	}

	public boolean getSupp(String name) {
        if(supplierDB.searchSupplierByName(name)==null)
        	return false;
        else
        	return true;
	}
	
	public void newSupp(String id, String name, String phone, String mail, String address, String city, String zip, String country)
	{
		//make something with this in the model layer / DB and add to table in suppliers
		
	}
	
	public String suppInfo(String idSelected)
	{
        return supplierDB.searchSupplierById(Integer.valueOf(idSelected)).getAddress() + " " + supplierDB.searchSupplierById(Integer.valueOf(idSelected)).getEmail();
		//find supplier with input ID and system.out.println the data formatted like this:
		/*
		 * ID: 'xxx'
		 * Name: '+name'
		 * and so on... 
		 */
	}

	public boolean deleteSupplier(String idSelected) {
		return true; //if deleted... basically anyhow. if it turns out to be false, we're fuced. and the program with simply crash. so make it work Guys pls :D
					 //and do the deleting part
	}


	public boolean deleteProduct(String id)
	{
		return true; //if you deleted the wanted one and do the deleting part
	}


	public boolean getProd(String name)
	{
		if(productDB.searchProductByName(name)==null)
			return false;
		else
			return true;
	}

	public String prodInfo(String idSelected) {
		//find product with input ID and system.out.println the data formatted like this:
				/*
				 * ID: 'xxx'
				 * Name: '+name'
				 * and so on... 
				 */
				//return "Works";
				Product p = new Product();
				p=productDB.searchProductById(Integer.valueOf(idSelected));
				return "ID: " + p.getProductId() +
						" name: " + p.getName() +
						" stock: " + p.getStockAmount() +
						" description: " + p.getDescription();
	}

	public void newCloth(String id, String name, Double purchP, Double salesP, Double rentP, Integer minStock, Integer quantity, String cOfO, String suppID, String size, String colour) {
		//add clothing to db
		
	}

	public void newEquip(String id, String name, Double purchP, Double salesP, Double rentP, Integer minStock, Integer quantity, String cOfO, String suppID, String type) {
		//add equipment to db
		
	}

	public void newGun(String id, String name, Double purchP, Double salesP, Double rentP, Integer minStock, Integer quantity, String cOfO, String suppID, String fabric, String calibre) {
		//add gun to db
		
	}

	public void newOrder(String id, String cusID, String delDay, String payDay, int total, String date) {
		SalesOrder so = new SalesOrder();
		so.setAmount(total);
		so.setC(customerDB.getCustomerById(Integer.valueOf(cusID)));
		so.setCreationDate(Date.valueOf(date));
		so.setPaymentDate(Date.valueOf(payDay));
		try {
			salesOrderDB.insertSalesOrder(so);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void deleteOrder(String idSelected) {
		//delete order!
		salesOrderDB.deleteSalesOrder(salesOrderDB.searchSalesOrder(Integer.valueOf(idSelected)));
	}

	public String orderInfo(String idSelected) {
		return "works";
		//find product with input ID and system.out.println the data formatted like this:
		/*
		 * ID: 'xxx'
		 * Name: '+name'
		 * and so on... 
		 */
	}
}
